<?php
	header('Content-Type:text/html;charset=utf-8');
	if(!defined('ROOT_PATH'))
		define('ROOT_PATH', dirname(__FILE__));
	require(ROOT_PATH."/define.php");  
	//require(ROOT_PATH."/includes/function.php");
  
	$db = new mysqli($db_host, $db_user, $db_pass, $db_name); 
	if($db->connect_errno)
	{
		if($debug)
			echo '连接数据库失败:'.$db->connect_error;
		else
			echo '错误：错误编号：ERROR_001';
		exit();
	}

	$num=$_REQUEST['num'];
  
	if(!isset($num))
	{
		echo "金额不能为空";
		
		$db->close(); 
		
		exit();
	}
	if(!is_num($num))
	{
		echo "金额必须为数字";
		
		$db->close();
		
		exit();
	}

	$yh_id=$_REQUEST['id'];
	if(!isset($yh_id))
	{
		echo "用户不能为空";
		
		$db->close();
		
		exit();
	}
	if(!is_num($yh_id))
	{
		echo "用户为非法字符";
		
		$db->close();
		
		exit();
	}

	$pass=$_REQUEST['pass'];
	if(!isset($pass))
	{
		echo "密码不能为空";
		
		$db->close(); 
		
		exit();
	}
	if(!preg_match('/^[A-Z]{10}$/i', $pass))
	{
		echo "密码格式错误";
		
		$db->close();
		
		exit();
	}
  
	$yh_lb=$_REQUEST['yh_lb'];
	if(!isset($yh_lb))
	{
		echo "用户类别不能为空";
		
		$db->close();
		
		exit();
	}
	if(!is_num($yh_lb))
	{
		echo "用户类别为非法字符";
		
		$db->close();
		
		exit();
	}
	if(intval($yh_lb)!=1&&intval($yh_lb)!=2)
	{
		echo "用户类别格式错误";
		
		$db->close();
		
		exit();
	}

	if($yh_lb==1)
		$sql_str="select rujin_zu_id,gt_jujian_id from yonghu where id=".strval($yh_id)." and suiji_pass='".strval($pass)."'";
	else
		$sql_str="select rujin_zu_id,gt_jujian_id from jujian where id=".strval($yh_id)." and suiji_pass='".strval($pass)."'";
	$result  = $db->query($sql_str);
	if(!$result)
	{
		if($debug)
			echo '查询用户基本信息错误：'.$db->error;
		else
			echo '错误：错误编号：ERROR_003';
			
		$result->close();
		$db->close();
		  
		exit();
	}
	if(mysqli_num_rows($result)<=0)
	{
		echo "登陆失败，用户名或密码错误";
			
		$result->close();
		$db->close();
			
		exit();
	}
	$row = $result->fetch_row();	
	$rujin_zu_id   = $row[0];
	$gt_jujian_id  = $row[1];
	$result->close();
	
	if($yh_lb==1)
		$sql_str="select id from yonghu where sj_xulie like '%,706,%' and id=".$yh_id;
	else
		$sql_str="select id from jujian where sj_xulie like '%,706,%' and id=".$yh_id;
	$result  = $db->query($sql_str);
	if(!$result)
	{
		if($debug)
			echo '查询用户基本信息错误：'.$db->error;
		else
			echo '错误：错误编号：ERROR_003';
			
		$result->close();
		$db->close();
		  
		exit();
	}
	if(mysqli_num_rows($result)<=0)
		$tt28_bz = 0;
	else
		$tt28_bz = 1;
	$result->close();
	
	if($yh_lb==1)
		$sql_str="select id from yonghu where (sj_xulie like '%,295,%' or  sj_xulie like '%,856,%'  or sj_xulie like '%,1054,%') and id=".$yh_id;
	else
		$sql_str="select id from jujian where (sj_xulie like '%,295,%' or  sj_xulie like '%,856,%'  or sj_xulie like '%,1054,%') and id=".$yh_id;
	$result  = $db->query($sql_str);
	if(!$result)
	{
		if($debug)
			echo '查询用户基本信息错误：'.$db->error;
		else
			echo '错误：错误编号：ERROR_003';
			
		$result->close();
		$db->close();
		  
		exit();
	}
	if(mysqli_num_rows($result)<=0)
		$xiaoyang_bz = 0;
	else
		$xiaoyang_bz = 1;
	$result->close();
	
	if($yh_lb==1)
	{
		if($gt_jujian_id==3)
			$sql_str = "update yonghu set rujin_zu_id=2 where id=".$yh_id;
		else
		{
			if($xiaoyang_bz==1)
				$sql_str = "update yonghu set rujin_zu_id=3 where id=".$yh_id;
			else
				$sql_str = "update yonghu set rujin_zu_id=1 where id=".$yh_id;
		}		
	}
	else
	{
		if($gt_jujian_id==3)
			$sql_str = "update jujian set rujin_zu_id=2 where id=".$yh_id;
		else
		{
			if($xiaoyang_bz==1)
				$sql_str = "update jujian set rujin_zu_id=3 where id=".$yh_id;
			else
				$sql_str = "update jujian set rujin_zu_id=1 where id=".$yh_id;
		}		
	}

	$update_bz	= $db->query($sql_str);
	if(!$update_bz)
	{
		if($debug)
			echo '查询支付接口信息错误：'.$db->error;
		else
			echo '错误：错误编号：ERROR_009';
			
		$db->close();
			  
		exit();
	}
	
	$sql_str="select bh from jujian where id=".strval($gt_jujian_id);
	$result  = $db->query($sql_str);
	if(!$result)
	{
		if($debug)
			echo '查询支付接口信息错误：'.$db->error;
		else
			echo '错误：错误编号：ERROR_009';
			
		$result->close();
		$db->close();
		  
		exit();
	}
	if(mysqli_num_rows($result)<=0)
	{
		if($debug)
			echo '找不到支付接口信息';
		else
			echo '错误：错误编号：ERROR_010';
			
		$result->close();
		$db->close();
			
		exit();
	}
	$row = $result->fetch_row();
	$order_bh   = $row[0];
	$result->close();
	
	$sql_str="select churu_jiekou.id,churu_jiekou.logo from rujin_zu_detail left join churu_jiekou on rujin_zu_detail.churu_id=churu_jiekou.id where rujin_zu_detail.rujin_zu_id=".$rujin_zu_id." and rujin_zu_detail.wap_bz=0 and churu_jiekou.bz=1";
	$result  = $db->query($sql_str);
	if(!$result)
	{
		if($debug)
			echo '查询用户基本信息错误：'.$db->error;
		else
			echo '错误：错误编号：ERROR_003';
			
		$result->close();
		$db->close();
		  
		exit();
	}
	if(mysqli_num_rows($result)<=0)
	{

		if($debug)
			echo '查询用户基本信息错误：'.$db->error;
		else
			echo '错误：错误编号：ERROR_003';
			
		$result->close();
		$db->close();
			
		exit();
	}

	$order_no=$order_bh.date('YmdHis').rand(10,99);

  ?>
<html>
	<head lang="en">
		<meta charset="UTF-8">
		<title></title>
		<link href="bank_select/css/bootstrap.min.css" rel="stylesheet" type="text/css">
		<script type="text/javascript" src="bank_select/js/jquery-1.11.3.min.js"></script>
		<style>
        body {
            background-color: #eff0f1;
            padding-top: 134px;
            padding-bottom: 110px;
            font-family: "微软雅黑", sans-serif;
            font-size: 14px;
        }

        .f_color_f60 {
            color: #ff6600;
        }

        .main {
            background-color: #fff;
            width: 1406px;
            margin: 0 auto;
            padding: 156px 0px 178px 0px;
        }

        .main > div {
            width: 840px;
            margin: 0 auto;
            line-height: 52px;
        }

        .border_style {
            border-bottom: solid 1px #eee;
        }

        .padding_left_font {
            padding-left: 14px;
        }

        .order_number {
            color: #999;
        }

        .pay_amount {
            color: #666;
            font-size: 16px;
        }

        .pay_amount .amount {
            font-size: 36px;
            float: right;
            margin-right: 15px;
            font-weight: 700;
        }

        .pay_amount span {
            display: inline-block;
            vertical-align: middle;
        }

        .mode_payment {
            font-size: 16px;
            color: #666;
        }

        .mode_payment .check_pay_mode {
            font-size: 12px;
        }

        .pay_way_list {
            width: 750px;
            margin: 0 auto;
        }

        .pay_way_list .Common_mode_payment {
            line-height: 40px;
            margin-top: -20px;
        }

        .pay_way_list ul {
            padding: 0;
            margin: 0;
        }

        .pay_way_list ul li {
            padding: 0;
            margin: 0;
            list-style: none;
            float: left;
            //margin-left: 110px;
			margin-bottom:20px;
        }

        .pay_way_list ul li:first-child {
            margin-left: 0;
        }

        .pay_way_list ul li:before {
            display: inline-block;
            content: "";
            width: 14px;
            height: 14px;
            background-color: #ddd;
            border-radius: 100%;
            border: solid 2px #eff0f1;
        }

        .pay_way_list ul li.on:before {
            background-color: #f60;
            border: solid 2px #fc9;
        }

        .pay_mode input {
            color: #666;
            background-color: transparent;
            border: none;
            outline: none;
        }

        .pay_mode.on input {
            color: #f60;
        }

        .pay_safety {
            font-size: 12px;
            color: #666;

            line-height: 20px;
            margin-top: 70px;
        }

        .pay_safety label {
            font-weight: normal;
        }

        .pay_safety input {
            width: 14px;
            height: 14px;
            vertical-align: text-bottom;
        }

        .next_step a {
            display: inline-block;
            width: 204px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            background-color: #f60;
            color: #fff;
            font-size: 16px;
            text-decoration: none;
        }

        .logoin {
            color: #999;
            font-size: 12px;
            line-height: 18px;
        }

        .logoin > div {
            display: inline-block;
            width: 204px;
            text-align: right;
        }

        .logoin a {
            color: #f60;

        }

        .pay_way_list ul:before, .pay_way_list ul:after,
        .pay_amount:before, .pay_amount:after {
            content: "";
            display: table;
        }

        .pay_way_list ul:after,
        .pay_amount:after {
            clear: both;
        }
		</style>
	</head>
	<body>
		<div class="main">
			<div>
				<div class="order_number border_style padding_left_font"><span>订单编号：</span><span><?php echo $order_no; ?></span></div>
				<div class="pay_amount border_style padding_left_font"><span>付款金额：</span><span class="f_color_f60 amount"><?php echo $num; ?>¥</span></div>
				<div class="border_style">
					<div class="mode_payment padding_left_font"><span>支付方式"</span><span class="f_color_f60 check_pay_mode">请选择支付方式</span><span>"</span></div>
					<div class="pay_way_list">
						<ul class="border_style">
						<?php
							$row = $result->fetch_row();
							$on = 0;
							while($row)
							{
								if($on==0)
									echo '<li style="width:33%;" class="on" data="'.$row[0].'"><img src="'.$row[1].'" alt=""/></li>';
								else
									echo '<li style="width:33%;" class="" data="'.$row[0].'"><img src="'.$row[1].'" alt=""/></li>';
								$on =1;
								$row = $result->fetch_row();
							}
							$result->close();
							?>
						</ul>
					</div>
				</div>
				<div class="pay_safety">
					<label>安全检测成功！</label>
				</div>
				<div class="next_step"><a id='go' href="##">下一步</a></div>
			</div>
		</div>
		<script type="text/javascript">
			$(document).ready(function(){

				$(".pay_way_list li").on("click", function (){
					$(this).addClass("on").siblings().removeClass("on");
				});

				$(".pay_way_list .pay_mode").on("click", function(){
					$(this).addClass("on").siblings().removeClass("on");
					if($(this).hasClass("other_pay_mode"))
					{
						$(this).parent().find("ul li").removeClass("on")
					}
					else
					{
						$(this).parent().find("ul li:first-child").addClass("on")
					}
				});
				
				$('#go').click(function(){
					var bank_id=$('.on').attr('data');
					var yh_id='<?php echo $yh_id; ?>';
					var yh_lb='<?php echo $yh_lb; ?>';
					var pass='<?php echo $pass; ?>';
					var num='<?php echo $num; ?>';
					var order_no='<?php echo $order_no; ?>'

					var pay_url='rujin_tiao.php?id='+yh_id+'&pass='+pass+'&yh_lb='+yh_lb+'&num='+num+'&jiekou_id='+bank_id+'&order_no='+order_no;

					$('#go').attr('href',pay_url);
					
				});
			});
			
		</script>
	</body>
</html>